import axios from "axios"

const baseURL = 'http://localhost:8888/api/private/v1/'
axios.defaults.baseURL = baseURL

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 将token给到一个前后台约定好的key中，作为请求发送
  let token = localStorage.getItem('mytoken')
  if (token) {
    config.headers['Authorization'] = token
  }
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

//登录
export  const checkUser=params=>{
  return axios.post("login",params).then(res=>res.data)
}
//获取用户列表
export const getUserList = params => {
  return axios.get("users", params).then(res => res.data)
}
//添加用户
export const addUserSubmit = params => {
  return axios.post("users", params).then(res => res.data)
}
//更改用户状态

export const changeUserState = params => {
  return axios.put(`users/${params.uId}/state/${params.type}`).then(res => res.data)
}
//根据id获取用户信息
export const getUserById = params => {
  return axios.get(`users/${params}`).then(res => res.data)
}
///根据id编辑用户
export const edittUserById = params => {
  return axios.put(`users/${params.id}`,params).then(res => res.data)
}
//删除用户
export const deleteUser = params => {
  return axios.delete(`users/${params}`).then(res => res.data)
}
//获取角色
export const getRoleList = params => {
  return axios.get("roles").then(res => res.data)
}
//分配用户角色
export const grandUserRole = params => {
  return axios.put(`users/${params.id}/role`,params).then(res => res.data)
}
//获取权限列表
export const getRightsList = params => {
  return axios.get(`rights/${params.type}`).then(res => res.data)
}
//删除权限
export const delRightsList = params => {
  return axios.delete(`roles/${params.roleId}/rights/${params.rightId}`).then(res => res.data)
}
//修改权限

export const grandRightList = (roleId, rids) => {
  return axios.post(`roles/${roleId}/rights`, rids).then(res => res.data)
}
//获取左侧菜单
export const getMenu = params => {
  return axios.get('menus').then(res => res.data)
}
//获取商品分类
export const getCategrory = params => {
  return axios.get('categories',params).then(res => res.data)
}
//添加商品

export const addCategrory = params => {
  return axios.post('categories',params).then(res => res.data)
}

